package com.xiaoxin.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaoxin.dubbo.mappers.UserMapper;
import com.xiaoxin.model.domain.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xiaoxiaode
 * @date 2021-08-28-14:54
 **/
@Slf4j
@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    public User findByMobile(String mobile) {
        // 根据手机号码查询
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("mobile", mobile);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void savePhone(User user, String phone) {
        user.setMobile(phone);
        userMapper.updateById(user);
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public User findById(Long userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public User findByhuanxinId(String huanxinId) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("hx_user", huanxinId);
        return userMapper.selectOne(wrapper);
    }

}
